#ifndef PICTURE_20180107
#define PICTURE_20180107

#include "../physical/physical.h"


class Picture
{
private:
	GLuint* m_textures;

	unsigned int m_textureIndex;
    unsigned int m_currentFrame;
    unsigned int m_numberOfFrames;

    bool m_useTransparency;
    bool m_isSpriteSheet;

    Size m_size;

public:
	Picture(unsigned int numberOfTextures);
	~Picture();

public:
	Size getSize(){return m_size;}
	void setSize(GLfloat width,GLfloat height){
		m_size.width = width;
		m_size.height = height;
	}

	GLuint getCurrentFrame()
	{
		return m_isSpriteSheet ? m_textures[0] : m_textures[m_currentFrame];
	}

    unsigned int getCurrentFrameIndex()
    {
        return m_currentFrame;
    }

    void setCurrentFrameIndex(unsigned int index)
    {
        if(index >= m_textureIndex)
            return;
        m_currentFrame = index;
    }

	void setNumberOfFrames(unsigned int frames)
	{
		m_numberOfFrames = frames;
	}

	unsigned int getNumberOfFrames(){return m_numberOfFrames;}

public:
	bool addTexture(const char* fileName,bool useTransparency = true);
	void render(GLfloat x,GLfloat y);
};



class PictureCommon
{
public:
    PictureCommon()
    {
        m_size.width = 0.0f;
        m_size.height = 0.0f;
    }

    virtual ~PictureCommon(){};
private:
    Size m_size;

public:
    const Size& getSize()const
    {
        return m_size;
    }

    void setSize(GLfloat width,GLfloat height)
    {
        m_size.width = width;
        m_size.height = height;
    }

    void setSize(Size size)
    {
        setSize(size.width , size.height);
    }

};


class SinglePicture : public PictureCommon
{
public:
    SinglePicture();
    virtual ~SinglePicture() override{}

protected:
    GLuint m_texture;

public:
    GLuint getTexture()const{return m_texture;}

    bool loadTexture(const char* fileName);
};


class MultiPicture : public PictureCommon
{
public:
    MultiPicture(unsigned int numberOfPictures);
    virtual ~MultiPicture() override;

protected:
    GLuint* m_textures;
    unsigned int m_numberOfPictures;
    unsigned int m_textureIndex;

public:
    GLuint getTexture(unsigned int index)const;

    unsigned int getTextureIndex()const
    {
        return m_textureIndex;
    }
    unsigned int getNumberOfPictures()const
    {
        return m_numberOfPictures;
    }

    bool loadTexture(const char* fileName);
};


#endif
